package sicnu.cs.ich.activity.rest;

import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import sicnu.cs.ich.activity.service.IActivityLikeService;
import sicnu.cs.ich.activity.service.IActivityService;
import sicnu.cs.ich.api.common.ResultInfo;
import sicnu.cs.ich.api.common.annotations.OperLog;
import sicnu.cs.ich.api.common.enums.OperEnum;
import sicnu.cs.ich.api.domain.dto.ActivityDTO;
import sicnu.cs.ich.api.domain.form.PageParam;
import sicnu.cs.ich.api.domain.vo.ActivityDetailVO;
import sicnu.cs.ich.common.util.ResultInfoUtil;

import java.util.List;
import java.util.Map;

/**
 * @author 黎琦
 * @date 2021-11-26 11:54
 */
@RestController
@Slf4j
@RequiredArgsConstructor
@RequestMapping("/auth/activity")
@Api(tags = {"AUTH-活动相关操作"})
public class AuthActivityResource {
    private final IActivityService activityService;
    private final IActivityLikeService activityLikeService;

    @GetMapping("/list")
    @ApiOperation("获取活动列表")
//    @OperLog(module = "号召活动模块",type = OperEnum.QUERY)
    public ResultInfo<PageInfo<ActivityDTO>> activities(PageParam param){
        if(param==null){
            return ResultInfoUtil.buildError("没有页号和每页显示条数哦");
        }
        return ResultInfoUtil.buildSuccess(activityService.getAllActivity(param));
    }

    @GetMapping("/detail")
    @ApiOperation("获取活动详情")
    public ResultInfo<ActivityDetailVO> getActivityDetail(@RequestParam("acID") Integer aid){
        if(aid==null){
            return ResultInfoUtil.buildError("没有活动id哦");
        }
        return ResultInfoUtil.buildSuccess(activityService.getActivityDetail(aid));
    }

    @GetMapping("/rankNeed")
    @ApiOperation("获取计算活动热度排行榜所需数据")
    public ResultInfo<List<Map<Integer,Long>>> rankNeedData(){
        List<Map<Integer, Long>> maps = activityLikeService.allActivityCommentNumAndLikeNum();
        maps.add(activityService.allActivityParticipantNum());
        return ResultInfoUtil.buildSuccess(maps);
    }
}
